package com.hyts.serialize.factory;

import com.hyts.serialize.base.BeanFactory;
import com.hyts.serialize.bean.JdkBean;
import com.hyts.serialize.config.SerializeConfig;
import lombok.Builder;

import java.io.*;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.serialize.factory
 * author:Libo/Alex
 * create-date:2019-06-21 21:58
 * copyright:libo-hyts-github
 * email:libo2dev@aliyun.com
 * description:此类主要用于: jdk bean对象服务工厂方法对象类
 */
@Builder
public class JdkBeanFactory implements BeanFactory<JdkBean,JdkBean> {



    @Override
    public JdkBean create(JdkBean param) {
        return param;
    }


    @Override
    public JdkBean create() {
        JdkBean param = new JdkBean();
        param.setDataLength(SerializeConfig.DEFAULT_SERIALIZE_DATA_SIZE);
        try {
            param.setByteArrayOutputStream(new ByteArrayOutputStream());
            param.setObjectOutputStream(new ObjectOutputStream(param.getByteArrayOutputStream()));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return param;
    }
}
